package servlet;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.time.LocalDateTime;

@WebServlet("/datetime")
public class datatime  implements Servlet {
    private LocalDateTime datetime;

    @Override
    public void init(ServletConfig servletConfig) throws ServletException { }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
             datetime=LocalDateTime.now();
             servletResponse.setCharacterEncoding("UTF-8");
             PrintWriter writer=servletResponse.getWriter();
             writer.print("<!DOCTYPE html>\n"+
                     "<html lang=\"en\">"+
                     "<head>"+
                     "<meta charset=\"UTF-8\">"+
                     "<title>Title</title>"+
                     "</head>"+
                     "<body>"+
                     "<div>当前时间：</div>"+ datetime +
                     "</body>"+
                     "</html>");
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
